define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'order/order_item/index' + location.search,
                    add_url: 'order/order_item/add',
                    edit_url: 'order/order_item/edit',
                    del_url: 'order/order_item/del',
                    multi_url: 'order/order_item/multi',
                    import_url: 'order/order_item/import',
                    table: 'order_item',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                fixedColumns: true,
                fixedRightNumber: 1,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'user_id', title: __('User_id')},
                        {field: 'order_id', title: __('Order_id')},
                        {field: 'goods_id', title: __('Goods_id')},
                        {field: 'content', title: __('Content'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'goods_title', title: __('Goods_title'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'goods_image', title: __('Goods_image'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image},
                        {field: 'goods_images', title: __('Goods_images'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.images},
                        {field: 'goods_original_price', title: __('Goods_original_price'), operate:'BETWEEN'},
                        {field: 'goods_price', title: __('Goods_price'), operate:'BETWEEN'},
                        {field: 'goods_num', title: __('Goods_num')},
                        {field: 'rights_title', title: __('Rights_title'), operate: 'LIKE'},
                        {field: 'rights_card', title: __('Rights_card'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'rights_tags', title: __('Rights_tags'), operate: 'LIKE', formatter: Table.api.formatter.flag},
                        {field: 'tags', title: __('Tags'), operate: 'LIKE', formatter: Table.api.formatter.flag},
                        {field: 'rights_num', title: __('Rights_num')},
                        {field: 'used_num', title: __('Used_num')},
                        {field: 'canuse_num', title: __('Canuse_num')},
                        {field: 'rights_content', title: __('Rights_content')},
                        {field: 'pay_price', title: __('Pay_price'), operate:'BETWEEN'},
                        {field: 'total_fee', title: __('Total_fee'), operate:'BETWEEN'},
                        {field: 'pay_status', title: __('Pay_status')},
                        {field: 'total_amount', title: __('Total_amount'), operate:'BETWEEN'},
                        {field: 'aftersale_status', title: __('Aftersale_status'), searchList: {"-1":__('Aftersale_status -1'),"0":__('Aftersale_status 0'),"1":__('Aftersale_status 1'),"2":__('Aftersale_status 2')}, formatter: Table.api.formatter.status},
                        {field: 'comment_status', title: __('Comment_status'), searchList: {"0":__('Comment_status 0'),"1":__('Comment_status 1')}, formatter: Table.api.formatter.status},
                        {field: 'total_price', title: __('Total_price'), operate:'BETWEEN'},
                        {field: 'refund_status', title: __('Refund_status'), searchList: {"-1":__('Refund_status -1'),"0":__('Refund_status 0'),"1":__('Refund_status 1'),"2":__('Refund_status 2')}, formatter: Table.api.formatter.status},
                        {field: 'refund_fee', title: __('Refund_fee'), operate:'BETWEEN'},
                        {field: 'refund_msg', title: __('Refund_msg'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'hospital_ids', title: __('Hospital_ids'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'express_name', title: __('Express_name'), operate: 'LIKE'},
                        {field: 'express_code', title: __('Express_code'), operate: 'LIKE'},
                        {field: 'express_no', title: __('Express_no'), operate: 'LIKE'},
                        {field: 'total_num', title: __('Total_num')},
                        {field: 'ext', title: __('Ext'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'order.order_sn', title: __('Order.order_sn'), operate: 'LIKE'},
                        {field: 'user.nickname', title: __('User.nickname'), operate: 'LIKE'},
                        {field: 'user.mobile', title: __('User.mobile'), operate: 'LIKE'},
                        {field: 'operate', title: __('Operate'),
                            table: table, events: Table.api.events.operate,
                            formatter: Table.api.formatter.operate,
                            buttons:[  {
                                name: 'send',
                                text: '',
                                title:'详情',
                                icon: 'fa fa-eye',
                                classname: 'btn btn-xs btn-warning btn-dialog chakan',
                                url: 'order/order_item/detail'
                            },
                            ]

                        }
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        recyclebin: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    'dragsort_url': ''
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: 'order/order_item/recyclebin' + location.search,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {
                            field: 'deletetime',
                            title: __('Deletetime'),
                            operate: 'RANGE',
                            addclass: 'datetimerange',
                            formatter: Table.api.formatter.datetime
                        },
                        {
                            field: 'operate',
                            width: '140px',
                            title: __('Operate'),
                            table: table,
                            events: Table.api.events.operate,
                            buttons: [
                                {
                                    name: 'Restore',
                                    text: __('Restore'),
                                    classname: 'btn btn-xs btn-info btn-ajax btn-restoreit',
                                    icon: 'fa fa-rotate-left',
                                    url: 'order/order_item/restore',
                                    refresh: true
                                },
                                {
                                    name: 'Destroy',
                                    text: __('Destroy'),
                                    classname: 'btn btn-xs btn-danger btn-ajax btn-destroyit',
                                    icon: 'fa fa-times',
                                    url: 'order/order_item/destroy',
                                    refresh: true
                                }
                            ],
                            formatter: Table.api.formatter.operate
                        }
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },

        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
